<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActionDispatch::Reloader</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../css/github.css" type="text/css" media="screen" />
<script src="../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Class</span> 
            ActionDispatch::Reloader 
            
                <span class="parent">&lt; 
                    
                    <a href="../Object.html">Object</a>
                    
                </span>
            
        </h1>
        <ul class="files">
            
            <li><a href="../../files/actionpack/lib/action_dispatch/middleware/reloader_rb.html">actionpack/lib/action_dispatch/middleware/reloader.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  
    <div class="description">
      
<p><a href="Reloader.html">ActionDispatch::Reloader</a> provides prepare and
cleanup callbacks, intended to assist with code reloading during
development.</p>

<p>Prepare callbacks are run before each request, and cleanup callbacks after
each request. In this respect they are analogs of
ActionDispatch::Callback’s before and after callbacks. However, cleanup
callbacks are not called until the request is fully complete – that is,
after close has been called on the response body. This is important for
streaming responses such as the following:</p>

<pre class="ruby"><span class="ruby-keyword">self</span>.<span class="ruby-identifier">response_body</span> = <span class="ruby-identifier">lambda</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">response</span>, <span class="ruby-identifier">output</span><span class="ruby-operator">|</span>
  <span class="ruby-comment"># code here which refers to application models</span>
}
</pre>

<p>Cleanup callbacks will not be called until after the response_body lambda
is evaluated, ensuring that it can refer to application models and other
classes before they are unloaded.</p>

<p>By default, <a href="Reloader.html">ActionDispatch::Reloader</a> is
included in the middleware stack only in the development environment;
specifically, when <code>config.cache_classes</code> is false. <a
href="Callbacks.html">Callbacks</a> may be registered even when it is not
included in the middleware stack, but are executed only when
<code>ActionDispatch::Reloader.prepare!</code> or
<code>ActionDispatch::Reloader.cleanup!</code> are called manually.</p>

    </div>
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>C</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Reloader.html#method-i-call">call</a>,
              </li>
            
              
              <li>
                <a href="Reloader.html#method-c-cleanup-21">cleanup!</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>N</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Reloader.html#method-c-new">new</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>P</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Reloader.html#method-c-prepare-21">prepare!</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>T</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Reloader.html#method-c-to_cleanup">to_cleanup</a>,
              </li>
            
              
              <li>
                <a href="Reloader.html#method-c-to_prepare">to_prepare</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  
    <!-- Includes -->
    <div class="sectiontitle">Included Modules</div>
    <ul>
      
        <li>
          
            <a href="../ActiveSupport/Callbacks.html">
              ActiveSupport::Callbacks
            </a>
          
        </li>
      
    </ul>
  



  

    

    

    


    


    <!-- Methods -->
    
      <div class="sectiontitle">Class Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-c-cleanup-21">
            
              <b>cleanup!</b>()
            
            <a href="Reloader.html#method-c-cleanup-21" name="method-c-cleanup-21" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Execute all cleanup callbacks.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-cleanup-21_source')" id="l_method-c-cleanup-21_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/72795d7257f3fbaaf235c6dad9a398bb1430de8d/actionpack/lib/action_dispatch/middleware/reloader.rb#L50" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-cleanup-21_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_dispatch/middleware/reloader.rb, line 50</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">cleanup!</span>
  <span class="ruby-identifier">new</span>(<span class="ruby-keyword">nil</span>).<span class="ruby-identifier">cleanup!</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-new">
            
              <b>new</b>(app, condition=nil)
            
            <a href="Reloader.html#method-c-new" name="method-c-new" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-new_source')" id="l_method-c-new_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/72795d7257f3fbaaf235c6dad9a398bb1430de8d/actionpack/lib/action_dispatch/middleware/reloader.rb#L54" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-new_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_dispatch/middleware/reloader.rb, line 54</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">initialize</span>(<span class="ruby-identifier">app</span>, <span class="ruby-identifier">condition</span>=<span class="ruby-keyword">nil</span>)
  <span class="ruby-ivar">@app</span> = <span class="ruby-identifier">app</span>
  <span class="ruby-ivar">@condition</span> = <span class="ruby-identifier">condition</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">lambda</span> { <span class="ruby-keyword">true</span> }
  <span class="ruby-ivar">@validated</span> = <span class="ruby-keyword">true</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-prepare-21">
            
              <b>prepare!</b>()
            
            <a href="Reloader.html#method-c-prepare-21" name="method-c-prepare-21" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Execute all prepare callbacks.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-prepare-21_source')" id="l_method-c-prepare-21_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/72795d7257f3fbaaf235c6dad9a398bb1430de8d/actionpack/lib/action_dispatch/middleware/reloader.rb#L45" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-prepare-21_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_dispatch/middleware/reloader.rb, line 45</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">prepare!</span>
  <span class="ruby-identifier">new</span>(<span class="ruby-keyword">nil</span>).<span class="ruby-identifier">prepare!</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-to_cleanup">
            
              <b>to_cleanup</b>(*args, &amp;block)
            
            <a href="Reloader.html#method-c-to_cleanup" name="method-c-to_cleanup" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Add a cleanup callback. Cleanup callbacks are run after each request is
complete (after close is called on the response body).</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-to_cleanup_source')" id="l_method-c-to_cleanup_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/72795d7257f3fbaaf235c6dad9a398bb1430de8d/actionpack/lib/action_dispatch/middleware/reloader.rb#L40" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-to_cleanup_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_dispatch/middleware/reloader.rb, line 40</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">to_cleanup</span>(*<span class="ruby-identifier">args</span>, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-identifier">set_callback</span>(<span class="ruby-value">:cleanup</span>, *<span class="ruby-identifier">args</span>, &amp;<span class="ruby-identifier">block</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-to_prepare">
            
              <b>to_prepare</b>(*args, &amp;block)
            
            <a href="Reloader.html#method-c-to_prepare" name="method-c-to_prepare" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Add a prepare callback. Prepare callbacks are run before each request,
prior to ActionDispatch::Callback’s before callbacks.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-to_prepare_source')" id="l_method-c-to_prepare_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/72795d7257f3fbaaf235c6dad9a398bb1430de8d/actionpack/lib/action_dispatch/middleware/reloader.rb#L34" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-to_prepare_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_dispatch/middleware/reloader.rb, line 34</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">to_prepare</span>(*<span class="ruby-identifier">args</span>, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-identifier">set_callback</span>(<span class="ruby-value">:prepare</span>, *<span class="ruby-identifier">args</span>, &amp;<span class="ruby-identifier">block</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                  
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-call">
            
              <b>call</b>(env)
            
            <a href="Reloader.html#method-i-call" name="method-i-call" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-call_source')" id="l_method-i-call_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/72795d7257f3fbaaf235c6dad9a398bb1430de8d/actionpack/lib/action_dispatch/middleware/reloader.rb#L60" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-call_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_dispatch/middleware/reloader.rb, line 60</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">call</span>(<span class="ruby-identifier">env</span>)
  <span class="ruby-ivar">@validated</span> = <span class="ruby-ivar">@condition</span>.<span class="ruby-identifier">call</span>
  <span class="ruby-identifier">prepare!</span>

  <span class="ruby-identifier">response</span> = <span class="ruby-ivar">@app</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">env</span>)
  <span class="ruby-identifier">response</span>[<span class="ruby-number">2</span>] = <span class="ruby-operator">::</span><span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">BodyProxy</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">response</span>[<span class="ruby-number">2</span>]) { <span class="ruby-identifier">cleanup!</span> }

  <span class="ruby-identifier">response</span>
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">Exception</span>
  <span class="ruby-identifier">cleanup!</span>
  <span class="ruby-identifier">raise</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    